home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / crunch22.zip / DEMO.C < prev    next >
Text File  |  1993-04-13  |  5KB  |  110 lines

  1. /* _________________________________________________________
  2.  
  3.     C R U N C H E R   D E M O   v2.2
  4.  
  5.     Here is an example of how to call the CRUNCHER's
  6.     libraries to perform any of the signal processing
  7.     techniques discussed in CRUNCH22.DOC.
  8.  
  9.     Copyright 1992,1993 by Gene V. Wallenstein
  10.     All rights reserved.
  11.    ________________________________________________________ */
  12.  
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <math.h>
  16.  
  17. float spectrum(float *,float *,int,float,int,int); /* Don't forget to declare the CRUNCHER routine. */
  18.  
  19. #define TRUE 1
  20. #define ITPTS 1024
  21.  
  22. main()
  23.      {
  24.      FILE *fptr1;
  25.      float infile[ITPTS],outfile[ITPTS],rate,freq;
  26.      int i,j,flag,win;
  27.      printf(" \n\n ---- CRUNCHER v2.2 DEMONSTRATION ----\n\n");   /* Blurb about the demo. */
  28.      printf(" Copyright 1992,1993 by Gene V. Wallenstein\n\n");
  29.      printf(" CRUNCHER v2.2 is a group of signal processing routines\n");
  30.      printf(" written for C programmers. Some of the routines included are:\n\n");
  31.      printf("  1) Fast Fourier Transform (FFT)  2) Digital Filtering of data\n");
  32.      printf("  3) Wavelet Transform (Affine)    4) Coherence Analysis\n");
  33.      printf("  5) Autocovariance                6) Crosscovariance\n");
  34.      printf("  7) Linear Regression             8) Moments Analysis\n");
  35.      printf("  9) Spectral Analysis            10) Cross Spectral Analysis\n");
  36.      printf(" 11) Wigner-Ville Transform\n\n");
  37.      printf(" This is a sample program which uses the SPECTRUM routine from\n");
  38.      printf(" the CRUNCHER. It performs a spectral analysis on the test data\n");
  39.      printf(" supplied with this kit and displays the power as a function of\n");
  40.      printf(" frequency.\n\n");
  41.      printf(" Hit the RETURN key to calculate the power spectrum\n");
  42.      printf(" of the test data using a Hanning window.");
  43.      getch();
  44.      printf(" \n\nO.K., give me a minute while I compute this...");
  45.  
  46.      if((fptr1=fopen("test.dat","r"))==NULL)
  47.        {printf("Sorry, I can't find the TEST.DAT file.");
  48.        exit(TRUE);}
  49.      for(i=0;i<=ITPTS-1;i++)  /* Initialize the arrays. */
  50.      {infile[i]=0.0;
  51.      outfile[i]=0.0;}
  52.      fptr1=fopen("test.dat","r");
  53.      i=1;
  54.      while(fscanf(fptr1,"%f",&infile[i]) != EOF )  /* Read in data starting at i=1 !! */
  55.        {i++;}
  56.  
  57.      flag = 0;     /* Power spectrum, not phase spectrum. */
  58.      win  = 1;     /* Use the Hanning window. */
  59.      rate = 64.0;  /* The sampling rate. */
  60.  
  61.      spectrum(infile,outfile,i-1,rate,flag,win);
  62.  
  63.      /* INFILE is a pointer to the infile array.
  64.     OUTFILE is a pointer to the results array.
  65.     i-1 is the number of points.
  66.      */
  67.  
  68.      printf("\nHere are the results, I'll go slow since the file is small (40 pts.).\n\n\n\n\n");
  69.  
  70.      printf("\x1B[22;24f");  /* ANSI stuff */
  71.      printf("Frequency");
  72.      printf("\x1B[22;37f");
  73.      printf("Power");
  74.      freq=0.0;
  75.      for(j=1;j<=i/2;j++)
  76.     {printf("\x1B[24;24f");
  77.     printf("%f",freq);
  78.     printf("\x1B[24;37f");
  79.     printf("%f",outfile[j]);
  80.     delay(350);
  81.     freq+=(rate/(float) i);}
  82.      printf(" \nPlease hit the RETURN key to continue...");
  83.      getch();
  84.      printf(" \n\n You are free to modify this program and try other routines\n");
  85.      printf(" that the CRUNCHER has to offer as long as the results are not used\n");
  86.      printf(" for commercial purposes. Please consult the CRUNCH22.DOC for more\n");
  87.      printf(" details regarding additional routines and their specifications.\n\n");
  88.      printf(" If you feel these routines are useful, please register by sending\n");
  89.      printf(" $25.00 to the address listed below. When you register you will receive:\n\n");
  90.      printf(" 1) FREE UPDATES -    Register once and you only pay postage and\n");
  91.      printf("                      handling for updates. NO EXTRA COSTS.\n\n");
  92.      printf(" 2) SOURCE CODE  -    You also get the complete source code to CRUNCHER.\n\n");
  93.      printf(" 3) ROYALTY FREE -    Registered users pay no royalties for commercial\n");
  94.      printf("                      products which use CRUNCHER routines.\n\n");
  95.      printf(" 4) MANUAL/TUTORIAL - Registered users will receive a laser printed\n");
  96.      printf("                      manual/tutorial on the techniques used by the CRUNCHER.\n\n");
  97.      printf(" Please hit the RETURN key to continue...");
  98.      getch();
  99.      printf(" \n\n If you have any questions concerning this product please don't\n");
  100.      printf(" hesitate to ask. I hope to hear from you soon.");
  101.      printf(" \n\n For further information or support contact:\n");
  102.      printf(" Internet   - Wallenstein@Walt.ccs.fau.edu\n");
  103.      printf(" Telephone  - (407) 750-3527\n");
  104.      printf(" CompuServe - 75110,77\n\n");
  105.      printf(" Gene V. Wallenstein\n");
  106.      printf(" 5990 Pine Cone Court, #406d1\n");
  107.      printf(" Lake Worth, FL. 33463 USA\n\n");
  108.      printf("\n\n Thank you for your interest in the CRUNCHER.\n");
  109. }
  110.